﻿using Huioo.Learning.Agile.Payroll.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Huioo.Learning.Agile.Payroll.Application
{
    /// <summary>
    /// 享受提成的雇员登记销售凭证
    /// </summary>
    public class SalesReceiptTransaction : Transaction
    {
        private readonly DateTime date;
        private readonly double amount;
        private readonly int empId;

        public SalesReceiptTransaction(DateTime date, double amount, int empId)
        {
            this.date = date;
            this.amount = amount;
            this.empId = empId;
        }

        public void Execute()
        {
            Employee e = PayrollDatabase.GetEmployee(empId);
            if (e == null)
                throw new InvalidOperationException("No such employee.");

            PaymentClassification pc = e.Classification as PaymentClassification;
            if (pc == null)
                throw new InvalidOperationException(
                    "Tried to add timecard to non-hourly employee");

            pc.AddSalesReceipt(new SalesReceipt(date, amount));
        }
    }
}
